package kr.hkit.androidcomplete02.ch15;

import kr.hyunist.androidcomplete01.R;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.View;

public class DrawUnitView extends View {
	
	public DrawUnitView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}
	
	public void onDraw(Canvas canvas){
		Paint pnt = new Paint();
		pnt.setColor(Color.YELLOW);
		Resources res = getResources();
		int width, height;
		int y = 0 ;
		
		//원론적인 방법
		DisplayMetrics dm = res.getDisplayMetrics();
		width = (int) (160 * dm.density);
		height = (int) (60 * dm.density);
		canvas.drawRect(0, y, width, y + height , pnt);
		y += (height * 1.2f);
		
		//dimen 리소스 이용
		width = (int) res.getDimension(R.dimen.drawunit_width);
		height = (int) res.getDimension(R.dimen.drawunit_height);
		canvas.drawRect(0, y, width, y+height, pnt);
		y += (height * 1.2f);
		
		//직접계산
		width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 160, dm);
		height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 60, dm);
		canvas.drawRect(0, y, width, y+height, pnt);
		y += (height * 1.2f);
	}

}
